Discovery Proxies for Managed Discovery
Ad
hoc discovery is a suitable approach for static and smaller local
service networks, where all services live on the same subnet and
multicasting probes or announcements don’t add a lot of network chatter.
Larger environments, with services distributed across multiple subnets (or highly dynamic networks), need to consider a Discovery Proxy to overcome the limitations of ad hoc probing. A Discovery Proxy can listen to UDP announcements on the standard udpAnnouncementEndpoint for service registration and de-registration, but also expose DiscoveryEndpoint via a WCF SOAP binding.
The implementation
requirements for a Discovery Proxy can vary from a simple implementation
that keeps an in-memory cache of available services, to implementations
that require databases or scale-out solutions, like caching extensions
provided by Windows Server AppFabric. WCF provides a DiscoveryProxy base class that can be used for general proxy implementations.
Discovering from a Discovery Proxy
Discovering services registered
with a Discovery Proxy follows the steps for ad hoc discovery discussed
earlier. Instead of multicasting a UDP message, DiscoveryClient now needs to contact the Discovery Proxy. Details about the discovery contract are encapsulated in the DiscoveryEndpoint class. Its constructor only takes parameters for the communication protocol details, binding, and address.
Here we are configuring a discovery client to query the Discover Proxy:
Example 9.
DiscoveryEndpoint proxyEndpoint = new DiscoveryEndpoint( new NetTcpBinding(), new EndpointAddress(proxyAddressText.Text)); this.discoveryClient = new DiscoveryClient(proxyEndpoint);
|
Implicit Service Discovery
Our
coverage of WCF Discovery so far has focused on the explicit discovery
of services. However, it is worth noting that WCF Discovery can also
perform the same queries behind-the-scenes, when you configure endpoints
as DynamicEndpoint
programmatically or in the configuration file. This allows for highly
dynamic, adaptive environments where virtually no location-specific
details are maintained as part of code or configuration.
The consistent application of the Service Discoverability
principle is vital for WCF Discovery features to be succesfully applied
across a service inventory, especially in regard to managed discovery.
The application of Canonical Expression ties directly to the definition and expression of any published service metadata. And, of course, Metadata Centralization represents the effective incorporation of a service registry as a central discovery mechanism.
|
A client endpoint, for example,
can be configured to locate a service that matches on scope and
contract. In the following example, we configure DynamicEndpoint to locate a service with matching contract and metadata:
Example 10.
<client> <endpoint kind="dynamicEndpoint" binding="basicHttpBinding" contract="ICustomerService" endpointConfiguration="dynamicEndpointConfiguration" name="dynamicCustomerEndpoint" /> </client> <standardEndpoints> <dynamicEndpoint> <standardEndpoint name="dynamicEndpointConfiguration"> <discoveryClientSettings> <findCriteria duration="00:00:05" maxResults="1"> <types> <add name="ICustomerService"/> </types> <extensions> <MyCustomMetadata> Highly Scalable </MyCustomMetadata> </extensions> </findCriteria> </discoveryClientSettings> </standardEndpoint> </dynamicEndpoint> </standardEndpoints>
|
With this configuration, the service consumer can create a proxy object to the server with the following code:
Example 11.
ICustomerService svc =
new ChannelFactory<ICustomerService>
("dynamicCustomerEndpoint").CreateChannel();